package com.project.service;

import java.util.List;

import com.project.dao.TaskDao;
import com.project.entity.Task;
import com.project.util.DateUtil;
import com.project.util.PKUtil;

public class TaskService {

	private TaskDao dao = new TaskDao();
	public void save(String begintime,String cont ,String deadtime,
			String level,String state,String name,String userid,int rate,String goalid) {
		
		Task task = new Task();
		
		task.setBegintime(begintime);
		task.setCont(cont);
		task.setCreatetime(DateUtil.getNow());
		task.setDeadtime(deadtime);
		task.setName(name);
		task.setId(PKUtil.getId());
		task.setLevel(level);
		task.setState(state);
		task.setUserid(userid);
		task.setRate(rate);
		task.setGoalid(goalid);
		
		dao.save(task);
	}
	
	public List<Task> findByGoalid(String goalid) {
		return dao.findByGoalid(goalid);
	}

	public Task findByTaskid(String taskid) {
		
		return dao.findByTaskid(taskid);
	}

	public boolean update(String id,String begintime,String cont ,String deadtime,
			String level,String state,String name,String userid,int rate) {
		
		Task task = new Task();
		task.setId(id);
		task.setBegintime(begintime);
		task.setCont(cont);
		task.setDeadtime(deadtime);
		task.setName(name);
		task.setLevel(level);
		task.setState(state);
		task.setUserid(userid);
		task.setRate(rate);
		
		return dao.update(task);
	}

	public List<Task> findByUserid(String userid,String state) {
		return dao.findByUserid(userid,state);
	}
}
